<template>
  <div class="inventoryDetail">
    <c-title :hide="false" text="库存明细"></c-title>
    <div class="shopList">
      <div class="lis">
        <div class="lis_l">
          <img v-if="stock.goods" :src="stock.goods.thumb" alt="" />
        </div>
        <div class="lis_r">
          <div class="title" v-if="stock.goods">{{ stock.goods.title }}</div>
          <div class="lis_r_b">
            <div class="lis_r_b_l">
              <div class="inventory">库存：{{ stock.stock }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="headTitle">库存明细</div>
    <div class="detailList" v-for="(item, index) in list" :key="index">
      <div class="detailList_t">
        <div class="detailList_t_l">{{ item.source_name }}</div>
        <div class="detailList_t_r">{{ item.created_at }}</div>
      </div>
      <div class="detailList_b">
        <div class="detailList_b_l">{{ item.source_name }}数量</div>
        <div class="detailList_b_r">{{ item.type == 1 ? "+" : "-" }}{{ item.change_stock }}</div>
      </div>
      <div class="detailList_b">
        <div class="detailList_b_l">{{ item.source_name }}价格</div>
        <div class="detailList_b_r">{{ $i18n.t("money") }}{{ item.order_price }}</div>
      </div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "../../utils/mixin";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      stock: [],
      list: [],
      page: 1,
      isLoadMore: false,
      total_page: 0
    };
  },
  activated() {
    this.getData();
  },
  methods: {
    getData() {
      $http
        .get(
          "plugin.gradevin-stock.frontend.controllers.index.stock-log",
          {
            goods_id: this.$route.params.id,
            page:this.page
          },
          ""
        )
        .then(
          response => {
            if (response.result === 1) {
              this.list = response.data.list.data;
              this.stock = response.data.stock;
            } else {
              this.$toast(response.msg);
            }
          },
          function(response) {
            console.log(response);
          }
        );
    },
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        $http
          .get("plugin.gradevin-stock.frontend.controllers.index.stock-log", {
            page: this.page,
            goods_id: this.$route.params.id
          })
          .then(response => {
            this.isLoadMore = true;
            if (response.result === 1) {
              var nextPageData = response.data.list.data;
              this.list = this.list.concat(nextPageData);
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
              this.$toast(r);
            }
          });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.inventoryDetail {
  .headTitle {
    font-size: 0.94rem;
    font-weight: bold;
    margin: 0 0.75rem;
    margin-top: 1.13rem;
    margin-bottom: 0.69rem;
    text-align: left;
  }
  .detailList {
    margin: 0 0.75rem;
    padding: 0.94rem 0.75rem 0.91rem 0.75rem;
    background: #fff;
    border-radius: 0.5rem;
    margin-bottom: 0.63rem;
    .detailList_t {
      display: flex;
      justify-content: space-between;
      padding-bottom: 0.97rem;
      border-bottom: 1px solid #f0f0f1;
      .detailList_t_l {
        font-weight: bold;
        font-size: 0.88rem;
      }
      .detailList_t_r {
        color: #6e6e79;
        font-size: 0.81rem;
      }
    }
    .detailList_b {
      display: flex;
      justify-content: space-between;
      margin-top: 0.94rem;
      .detailList_b_l {
        font-size: 0.81rem;
      }
      .detailList_b_r {
        color: #f15353;
        font-size: 0.81rem;
      }
    }
  }
  .shopList {
    padding: 0 0.75rem;
    box-sizing: border-box;
    .lis {
      display: flex;
      padding: 0.75rem;
      border-radius: 0.5rem;
      margin-top: 0.63rem;
      background: #fff;
      .lis_l {
        flex-shrink: 0;
        width: 5.63rem;
        height: 5.63rem;
        border-radius: 0.5rem;
        margin-right: 0.63rem;
        img {
          width: 5.63rem;
          height: 5.63rem;
          border-radius: 0.5rem;
        }
      }
      .lis_r {
        flex: 1;
        display: flex;
        flex-direction: column;
        .title {
          text-align: left;
          font-weight: 500;
          font-size: 0.88rem;
        }
        .lis_r_b {
          flex: 1;
          display: flex;
          justify-content: space-between;
          align-items: flex-end;
          .lis_r_b_l {
            height: 100%;
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            justify-content: space-between;
            flex: 1;
            text-align: left;
            font-size: 0.81rem;
            color: #6e6e79;
            .inventory {
              line-height: 1.25rem;
              margin-top: 0.7rem;
            }
            .myinventory {
              line-height: 1.25rem;
            }
          }
          .lis_r_b_r {
            width: 1.25rem;
            height: 1.25rem;
            background: #f15353;
            border-radius: 50%;
            .icon-icon_add {
              color: #fff;
              font-size: 0.65rem;
            }
          }
        }
      }
    }
  }
}
</style>
